let express = require('express');
let router = express.Router();
let finance = require('../service/finance');
let {create, getYear, getMonth, getToday, getAll, deleteRecord}
    = require('../service/finance');


router.post('/', function (req, res, next) {
    create(req.body, function () {
        getToday(function (today) {
            res.end(JSON.stringify(today));
        });
    })
});

router.post('/delete', (req, res, next) => {
    deleteRecord(req.body, (data) => {
        res.end(JSON.stringify(data))
    })
});


router.get('/', function (req, res, next) {
    getToday(function (today) {
        res.end(JSON.stringify(today))
    })
});

//get today's records
router.get('/today', (req, res, next) => {
    getToday(function (today) {
        res.end(JSON.stringify(today))
    })
});

router.get('/month', (req, res, next) => {
    getMonth((data) => {
        res.end(JSON.stringify(data));
    })
});

router.post('/year', (req, res, next) => {
    getYear(req.body, (data) => {
        res.end(JSON.stringify(data));
    })
});

router.get('/all', (req, res, next) => {
    getAll((data) => {
        res.end(JSON.stringify(data));
    })
});

module.exports = router;